import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter/material.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:overlay_support/overlay_support.dart';
import 'package:wowhy/services/navigate_service.dart';

import 'assets/images.dart';

import 'service_locator.dart';
import 'utils/local_storage.dart';
import 'services/auth_service.dart';

import 'widgets/splash_screen.dart';
import 'widgets/exit_pop_scope.dart';

import 'routes.dart';

Future<Widget> createApp() async {
  await LocalStorage.initialize();
  await AuthService.instance.interceptors();
  await AuthService.instance.isLogined();

  return App();
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final Widget app = OverlaySupport(
      child: MaterialApp(
        navigatorKey: getIt<NavigateService>().key,
        title: 'App',
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: ExitPopScope(
          child: SplashScreen(
            seconds: 5,
            navigateAfterSeconds: 'index',
            imageBackground: ImagesAssets.splash,
            backgroundColor: Colors.white,
            onClick: () => print("Flutter Egypt"),
          ),
        ),
        onGenerateRoute: buildRoute,
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
          PickerLocalizationsDelegate.delegate,
        ],
        supportedLocales: [
          const Locale('zh'),
          const Locale('en', 'US'),
        ],
      ),
    );

    return app;
  }
}
